package com.lqb.webScaffold.utils;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class MyRequest {
    public String post(String url,HashMap<String,Object> data){
        HttpRequest request = HttpUtil.createPost(url);
        for(Map.Entry<String,Object> entry : data.entrySet()){
            request.form(entry.getKey(),entry.getValue());
        }
        HttpResponse response = request.execute();
        System.out.println(response.toString());
        String responseBody = response.body();
        return responseBody;
    }
    public String get(String url,HashMap<String,Object> data){
        HttpRequest request = HttpUtil.createGet(url);
        for(Map.Entry<String,Object> entry : data.entrySet()){
            request.form(entry.getKey(),entry.getValue());
        }
        HttpResponse response = request.execute();
        System.out.println(response.toString());
        String responseBody = response.body();
        return responseBody;
    }


}
